/*
 * @Author: 孙大大
 * @Date: 2022-04-12 20:51:15
 * @LastEditTime: 2022-04-12 20:53:55
 * @FilePath: \黑马面面\mock\szw.js
 */
// 导入mockjs
const Mock = require("mockjs");
const count = 101;
const originList = [];
for (let i = 0; i < count; i++) {
  originList.push(
    Mock.mock({
      index: "@increment",
      bianhao: "@word(1)@id",
      tixing: "@pick(['简答','单选','多选'])",
      bianhao2: "@word(1)@id@word(1)@id",
      time: "@datetime",
      huida: "@integer(200, 1000)s",
      zhengque: "@integer(0, 100)%",
      people: "@cname",
    })
  );
}

Mock.mock("/api/tizu", "post", (params) => {
  const body = JSON.parse(params.body);
  let { page, pageSize, keyword } = body;
  const arr = [];
  originList.forEach((item) => {
    // console.log(item, "标志", keyword);
    if (item.bianhao.includes(keyword)) {
      arr.push(item);
    }
  });
  let total = arr.length;
  let len = total / pageSize;
  const totalPage = Number.isInteger(len) ? len + 1 : len;
  const list = arr.slice((page - 1) * pageSize, page * pageSize);
  return {
    code: 200,
    message: "success",
    data: {
      page,
      pageSize,
      total,
      totalPage,
      list,
    },
  };
});
Mock.mock("/api/del", "post", (body) => {
  const id = body.body;
  // const body = JSON.parse(params.body);
  // console.log(id, 2536);
  const index = originList.findIndex((item) => item.index === id);
  originList.splice(index, 1);
  return {
    code: 200,
    message: "删除成功",
  };
});
